// packageD/sharees/index.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        sharees: [{
            acountRemark: 0,
            addTime: "2025-06-25T08:39:57.966209",
            adminRemark: null,
            availAcount: 0,
            avatarUrl: "",
            bindingPeriod: "2025-06-25T08:39:57.966098",
            firstActiveTime: "0001-01-01T00:00:00",
            flag: false,
            freezingIntegral: 0,
            gender: 0,
            iDcardback: "",
            iDcardfront: "",
            iDnumber: "",
            id: 655,
            integral: 15,
            inviterId: 636,
            inviterNickname: "",
            isOld: true,
            isRegistered: false,
            lastActiveTime: "0001-01-01T00:00:00",
            lastUpdateTime: "2025-08-02T11:05:02.167056",
            myMoney: 0,
            nickname: "步游",
            openid: "opBcR0S9CfQeyFRKtnVXgycUzwPg",
            parentOpId: "",
            password: null,
            remark: null,
            roleId: 2,
            session_key: "SzHUZ18ETc6tJK3ySGhX+Q==",
            tenantId: 0,
            unPointAcount: 0,
            unionid: null,
            userName: null,
            userPhone: "13905174317",
            validateCode: "174317",
            vipFlag: 1,
            wXpayCodeUnlimitUrl: "",
            wxaCodeUnlimitUrl: "https://xssp.xjdio.com/images/UserQrCode/HRid174317.jpeg",
        }, {
            acountRemark: 0,
            addTime: "2025-06-10T18:55:51.24245",
            avatarUrl: "https://xssp.xjdio.com/images/Xjd/Category/001/20250210070627c755e78e-8a1b-48b3-8f85-7f8f68e903b1.png",
            isOld: true,
            isRegistered: false,
            lastActiveTime: "0001-01-01T00:00:00",
            lastUpdateTime: "2025-07-27T21:57:32.258229",
            myMoney: 0,
            nickname: "知行融合🍀软件开发",
            openid: "opBcR0cqxjNJFFXDuegeQDThRAas",
            parentOpId: "",
            password: null,
            remark: null,
            roleId: 2,
            session_key: "zYCJGWwfXB+Xipr+k83apg==",
            tenantId: 0,
            unPointAcount: 0,
            unionid: null,
            userName: null,
            userPhone: "19821375588",
            validateCode: "375588",
            vipFlag: 1,
            wXpayCodeUnlimitUrl: "",
            wxaCodeUnlimitUrl: "https://xssp.xjdio.com/images/UserQrCode/UserId627.jpeg",
        }],         // 分享记录列表,
        searchValue: '',     // 搜索框值
        isSearching: false,  // 是否在搜索状态
        page: 1,             // 当前页码
        hasMore: true        // 是否有更多数据
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        // this.loadSharees();
    },
    //查分享记录
    GetshareRecord(params) {
        return wx.Http.post('/AccountAppService/GetshareRecord', {
            PageIndex: params.page,
            PageSize: params.pageSize
        })
    },
    SearchshareRecord(param1, param2) {
        return wx.Http.post('/AccountAppService/SearchshareRecord', {
            PageIndex: param1,
            PageSize: 15,
            ValidateCode: param2
        })
    },
    filters: {
        phoneFilter: function (phone) {
            if (!phone) return '';
            if (phone.length < 7) return phone;
            return phone.substring(0, 3) + '****' + phone.substring(7);
        }
    },
    // 加载分享记录 = ''
    loadSharees(page = 1, searchValue) {
        const params = {
            page,
            pageSize: 15
        };
        wx.showLoading({ title: '加载中...' });
        // 添加搜索参数
        if (searchValue) {
            // params.lastSix = searchValue;
            this.SearchshareRecord(page, searchValue).then((res) => {
                if (res.data) {
                    console.log(res.data)
                    const data = res.data;
                    this.setData({
                        sharees: page === 1 ? data : [...this.data.sharees, ...data],
                        hasMore: data.length == this.data.pageSize ? true : false,
                        page,
                        isSearching: !!searchValue
                    });
                    wx.hideLoading();
                    wx.stopPullDownRefresh();
                } else {
                    this.setData({
                        sharees: [],
                        hasMore: false,
                        page,
                        isSearching: !!searchValue
                    });
                    wx.hideLoading();
                }
            })
        } else {
            this.GetshareRecord(params).then((res) => {
                if (res.data) {
                    console.log(res.data)
                    const data = res.data;
                    this.setData({
                        sharees: page === 1 ? data : [...this.data.sharees, ...data],
                        hasMore: data.length == this.data.pageSize ? true : false,
                        page,
                        isSearching: !!searchValue
                    });
                    wx.hideLoading();
                    wx.stopPullDownRefresh();
                } else {
                    this.setData({
                        sharees: [],
                        hasMore: false,
                        page,
                        isSearching: !!searchValue
                    });
                    wx.hideLoading();
                }
            })
        }



        // 调用API - 替换为你的实际API
        // wx.request({
        //     url: 'https://yourdomain.com/api/sharees',
        //     method: 'GET',
        //     data: params,
        //     header: {
        //         'Authorization': `Bearer ${wx.getStorageSync('token')}`
        //     },
        //     success: (res) => {
        //         if (res.data.code === 200) {
        //             const data = res.data.data;
        //             this.setData({
        //                 sharees: page === 1 ? data.list : [...this.data.sharees, ...data.list],
        //                 hasMore: data.hasMore,
        //                 page,
        //                 isSearching: !!searchValue
        //             });
        //         }
        //     },
        //     complete: () => {
        //         wx.hideLoading();
        //         wx.stopPullDownRefresh();
        //     }
        // });
    },

    // 输入框输入事件
    onInputSearch(e) {
        this.setData({ searchValue: e.detail.value });
    },

    // 搜索事件
    onSearch() {
        const _this = this;
        if (!this.data.searchValue || this.data.searchValue.length !== 6) {
            wx.showToast({ title: '请输入6位手机尾号', icon: 'none' });
            return;
        }
        this.SearchshareRecord(1, this.data.searchValue).then((res) => {
            let page = 1;
            if (res.data) {
                console.log(res.data)
                const data = res.data;
                _this.setData({
                    sharees: page === 1 ? data : [..._this.data.sharees, ...data],
                    hasMore: data.length == _this.data.pageSize ? true : false,
                    page,
                    isSearching: !!this.data.searchValue
                });
                wx.hideLoading();
                wx.stopPullDownRefresh();
            } else {
                _this.setData({
                    sharees: [],
                    hasMore: false,
                    page,
                    isSearching: !!this.data.searchValue
                });
                wx.hideLoading();
            }
        })
    },

    // 下拉刷新
    onRefresh() {
        this.loadSharees(1, this.data.searchValue ? this.data.searchValue : '');
    },

    // 上拉加载更多
    onReachBottom() {
        if (this.data.hasMore) {
            this.loadSharees(this.data.page + 1, this.data.searchValue ? this.data.searchValue : '');
        }
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})